﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Data;
using EpiNEXT.Foundation;
using EpiNEXT.Services;

namespace EpiNEXT.Applications
{
    public class CodeListViewModel : ObservableObject
    {
        #region Members
        private CodeList _codeList;
        private CodeListMode _codeListMode = CodeListMode.Basic;
        private object _listValuesLock = new object();
        #endregion Members

        #region Properties
        public CodeList CodeList
        {
            get
            {
                return this._codeList;
            }
            set
            {
                this._codeList = value;
            }
        }

        public Guid Id
        {
            get
            {
                return CodeList.Id;
            }
            set
            {
                CodeList.Id = value;
                RaisePropertyChanged("Id");
            }
        }

        public CodeListMode Mode
        {
            get
            {
                return CodeList.Mode;
            }
            set
            {
                CodeList.Mode = value;
                RaisePropertyChanged("Mode");
            }
        }

        public bool Concatenate
        {
            get
            {
                return CodeList.Concatenate;
            }
            set
            {
                CodeList.Concatenate = value;
                RaisePropertyChanged("Concatenate");
            }
        }

        public string Separator
        {
            get
            {
                return CodeList.Separator;
            }
            set
            {
                CodeList.Separator = value;
                RaisePropertyChanged("Separator");
            }
        }

        public ObservableCollection<CodeListValue> CodeListValues
        {
            get
            {
                return CodeList.CodeListValues;
            }
            set
            {
                CodeList.CodeListValues = value;
                RaisePropertyChanged("CodeListValues");
            }
        }

        public ICollectionView CodeListValuesView
        {
            get;
            set;
        }

        public string Name
        {
            get
            {
                return CodeList.Name;
            }
            set
            {
                CodeList.Name = value;
                RaisePropertyChanged("Name");
            }
        }
        #endregion // Properties

        #region Constructors
        public CodeListViewModel(CodeList codeList)
        {
            this.CodeList = codeList;
            CodeListValuesView = new CollectionViewSource { Source = CodeList.CodeListValues }.View;
            System.Windows.Data.BindingOperations.EnableCollectionSynchronization(CodeListValuesView, _listValuesLock);
        }
        #endregion // Constructors

        #region Methods
        public override string ToString()
        {
            return this.Name;
        }
        #endregion // Methods
    }
}
